Skip to content

Fix stale CodeEditor findController listener swap#107

Merged
MegatronKing merged 2 commits into
reqable:mainfrom
SebTardif:fix-f003-find-controller-listener-swap
Jun 2, 2026
Merged

Fix stale CodeEditor findController listener swap#107
MegatronKing merged 2 commits into
reqable:mainfrom
SebTardif:fix-f003-find-controller-listener-swap

Conversation

@SebTardif

@SebTardif SebTardif commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • remove _updateWidget from the previous findController before swapping controllers in CodeEditor.didUpdateWidget
  • add regression tests for stale notifications after a controller swap and after the editor is removed

Problem

When CodeEditor swaps to a new findController, didUpdateWidget() overwrites _findController before removing _updateWidget. That means the remove call targets the new controller instead of the old one, leaving the old controller able to keep rebuilding the editor after it has been detached.

Reproduction

  1. Build a CodeEditor with oldFindController
  2. Rebuild it with newFindController
  3. Trigger oldFindController.findMode()

Before this change, the stale controller still notifies the editor and causes an extra rebuild. If the editor is removed from the tree first, the stale controller can also trigger setState() after dispose.

Fix

Store the previous controller in a local variable, detach _updateWidget from that instance, then assign and subscribe the new controller.

Verification

  • red step: reverted the production fix, each regression test failed
  • green step: restored the fix, both regression tests passed
  • flutter test test/code_search_controller_test.dart
  • flutter analyze --no-fatal-infos lib/src/code_editor.dart test/code_search_controller_test.dart

Bug origin

  • introduced in b35627f on 2024-02-05

Follow-up improvements in this PR

SebTardif added 2 commits May 15, 2026 21:47
Remove _updateWidget from the previous findController before assigning the new controller in CodeEditor.didUpdateWidget(). Add a regression test that proves stale controllers no longer trigger rebuilds after a swap.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Add a regression test for stale findController notifications after the editor is removed.

Closes reqable#108

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@MegatronKing

Copy link
Copy Markdown
Member

LGTM, thank you!

@MegatronKing MegatronKing merged commit f362394 into reqable:main Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add regression coverage for stale findController callbacks after editor disposal

2 participants